<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\admin\service\ConfigService;
use app\common\libs\helper\FileHelper;
use think\facade\App;
use think\facade\View;

class Cache extends AdminController
{

    /**
     * 清除缓存
     *
     * @Author tanruizheng
     * @DateTime 2021-07-09
     * @return void
     */
    public function cache()
    {
       set_time_limit(0);
        //清除系统配置缓存
        ConfigService::clearConfigCache();
        $runtimePath = App::getRootPath().'runtime';
        //清除文件缓存
        $scandir = scandir($runtimePath);
        foreach($scandir as $key => $val){
            if($val != '.' && $val != '..'){
                //清除模板文件缓存
                if (file_exists($runtimePath.'/'.$val.'/temp')){
                    (new FileHelper())->deleteDir($runtimePath.'/'.$val.'/temp');
                }
                //清除网站日志缓存
                if (file_exists($runtimePath.'/'.$val.'/log')){
                    (new FileHelper())->deleteDir($runtimePath.'/'.$val.'/log');
                }
            }
        }
        return self::createSuccess('清除缓存成功',[],1);
        
    }
}
